﻿<UserControl x:Class="MusicExplorer.View.TrackList"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:internals="clr-namespace:MusicExplorer.Internals" DataContext="{Binding TrackList}"
             >
    
    <UserControl.Resources>
        <ResourceDictionary>
            <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
            <internals:FavoriteToStarConverter x:Key="FavoriteToStarConverter" />
            <internals:FavoriteAndSelectedToStarConverterVisibility x:Key="FavoriteAndSelectedToStarConverterVisibility" />
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="../Resources/Skins/TrackListSkin.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </UserControl.Resources>

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="30" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>

        <!-- Current selection property -->
        <Border BorderThickness="0, 0, 0, 1">
            <Border.BorderBrush>
                <SolidColorBrush>
                    <SolidColorBrush.Color>
                        <Color A="255" R="187" G="187" B="187" />
                    </SolidColorBrush.Color>
                </SolidColorBrush>
            </Border.BorderBrush>
            <Border.Background>
                <SolidColorBrush>
                    <SolidColorBrush.Color>
                        <Color A="255" R="250" G="250" B="250" />
                    </SolidColorBrush.Color>
                </SolidColorBrush>
            </Border.Background>
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="180" />
                </Grid.ColumnDefinitions>
                <TextBlock Text="{Binding TrackListTitle}" VerticalAlignment="Center" Margin="5, 0, 0, 0" FontFamily="Helvetica"
                           FontSize="14" Foreground="Black" FontWeight="SemiBold" />
                <ComboBox Grid.Column="1" ItemsSource="{Binding TrackListModes}" HorizontalContentAlignment="Stretch" Margin="0, 0, 2, 0"
                    SelectedItem="{Binding CurrentTrackListMode, Mode=TwoWay}" Height="25" VerticalContentAlignment="Center" HorizontalAlignment="Stretch" VerticalAlignment="Center">
                    <ComboBox.ItemTemplate>
                        <DataTemplate>
                            <StackPanel Orientation="Horizontal" Height="25" Margin="0, -3, 0, 0">
                                <Image Source="{Binding DisplayIcon}" Width="16" Height="16" VerticalAlignment="Center" />
                                <TextBlock Text="{Binding DisplayName}" VerticalAlignment="Center" Margin="5, 0, 0, 0" FontFamily="Helvetica" FontSize="14" />
                            </StackPanel>
                        </DataTemplate>
                    </ComboBox.ItemTemplate>
                </ComboBox>
            </Grid>
        </Border>

        <ListBox ItemsSource="{Binding Tracks}" x:Name="trackListView" Grid.Row="1"
            BorderBrush="Transparent" BorderThickness="0" VerticalContentAlignment="Center"
            VirtualizingPanel.IsVirtualizing="False" SelectedItem="{Binding SelectedTrack}">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <Grid Height="20">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="16" />
                            <ColumnDefinition Width="26" />
                            <ColumnDefinition Width="600" />
                            <ColumnDefinition Width="100" />
                        </Grid.ColumnDefinitions>

                        <Image Source="../Resources/Images/Icons/blackcircle.png" Height="8" Width="8" HorizontalAlignment="Left" Margin="0, 0, 5, 0"
                                Visibility="{Binding IsRead, Converter={StaticResource BooleanToVisibilityConverter}}" />

                        <Image Source="{Binding IsFavorite, Converter={StaticResource FavoriteToStarConverter}}" Margin="0, 0, 5, 0" Height="16" Width="16" VerticalAlignment="Center" HorizontalAlignment="Left"
                                       MouseLeftButtonDown="SetToFavorite" Grid.Column="1">
                            <Image.Visibility>
                                <MultiBinding Converter="{StaticResource FavoriteAndSelectedToStarConverterVisibility}">
                                    <Binding Path="IsFavorite" />
                                    <Binding Path="IsSelected" />
                                </MultiBinding>
                            </Image.Visibility>
                        </Image>

                        <TextBlock TextTrimming="CharacterEllipsis" Text="{Binding Title}" VerticalAlignment="Center" Grid.Column="2" />

                        <TextBlock TextWrapping="NoWrap" Text="{Binding PublishDate}" VerticalAlignment="Center" Grid.Column="3" />
                    </Grid>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
    </Grid>
</UserControl>
